﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using WebShopDAL;
using KlauserswagModel;

namespace ProjektarbeteKlauserSwag
{
    public partial class Login : System.Web.UI.Page
    {
        public bool IsLoggedIn { get; set; }
        public Login()
        {
            IsLoggedIn = false;
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            LabelUsernamePassword.Visible = false;
        }

        protected void ButtonLogin_Click(object sender, EventArgs e)
        {
            try
            {
                bool checkLogin = UserDB.IsLoggedIn(TextBoxUserName.Text, TextBoxPassword.Text);
                if (checkLogin == true)
                {
                    IsLoggedIn = true;

                    User currentUser = UserDB.GetCurrentUser(TextBoxUserName.Text.ToString(), TextBoxPassword.Text.ToString());
                    Session["CurrentUser"] = currentUser;

                    Response.Redirect("~/Home.aspx");
                }
                else
                {
                    IsLoggedIn = false;
                    LabelUsernamePassword.Visible = true;
                }
            }
            catch (Exception)
            {
            }
        }
    }
}